Skip to content

fix(funnels): update current step based on URL change#4407

Merged
ilasw merged 13 commits into
mainfrom
fix-back-history
Apr 17, 2025
Merged

fix(funnels): update current step based on URL change#4407
ilasw merged 13 commits into
mainfrom
fix-back-history

Conversation

@ilasw
Copy link
Copy Markdown
Contributor

@ilasw ilasw commented Apr 14, 2025

Changes

Listen also stepId on URL in order to update current step on back navigation

Events

Did you introduce any new tracking events?

Experiment

Did you introduce any new experiments?

Manual Testing

Caution

Please make sure existing components are not breaking/affected by this PR

Preview domain

https://fix-back-history.preview.app.daily.dev

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
daily-webapp ✅ Ready (Inspect) Visit Preview Apr 17, 2025 8:02am
1 Skipped Deployment
Name Status Preview Updated (UTC)
storybook ⬜️ Ignored (Inspect) Apr 17, 2025 8:02am

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

packages/shared/src/features/onboarding/hooks/useFunnelNavigation.ts:163

  • [nitpick] Consider renaming 'stepInURL' to 'urlStepId' for enhanced clarity, as it represents the stepId extracted from the URL.
const stepInURL = searchParams.get('stepId');

@ilasw ilasw changed the title fix: update current step based on URL change fix(funnels): update current step based on URL change Apr 15, 2025
@ilasw ilasw requested a review from Copilot April 15, 2025 09:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

packages/shared/src/features/onboarding/hooks/useFunnelNavigation.ts:163

  • Ensure that 'searchParams' reliably reflects the current URL state; if this value updates asynchronously, the extracted 'urlStepId' might become stale. Consider verifying that 'searchParams' is sourced from a reactive hook.
const urlStepId = searchParams.get('stepId');

packages/shared/src/features/onboarding/hooks/useFunnelNavigation.ts:178

  • [nitpick] Including 'urlStepId' in the dependency array is appropriate for reactivity; however, confirm that this does not lead to unnecessary re-renders if 'searchParams' remains stable across renders.
[funnel.id, urlStepId]

Comment thread packages/shared/src/features/onboarding/hooks/useFunnelNavigation.ts Outdated
Comment thread packages/shared/src/features/onboarding/hooks/useFunnelNavigation.ts Outdated
() => {
// Check if the URL has a stepId parameter or if there is a session
const stepId = searchParams.get('stepId') ?? session.currentStep;
const stepId = urlStepId ?? session.currentStep;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it not be better, if session.currentStep is different from stepid, then redirect to that /?step=session.currentStep

if not just have the step state in URL always?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is that the URL takes priority over currentStep from the session, since users can navigate through the steps.
I’d prefer not to introduce redirect logic here, as it’s very easy to end up in a loop with this kind of setup.

Copy link
Copy Markdown
Contributor

@capJavert capJavert Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this resolving be server side logic instead of useEffect, and then client part just gets the stepId in the atom? But leaving up to you guys since you are more familiar with system.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! I've moved this logic in the SSR ✔️

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

packages/webapp/pages/helloworld/index.tsx:79

  • Using a template literal for query?.stepId will yield the string 'undefined' when query.stepId is missing, causing unintended behavior. Consider replacing it with a nullish coalescing operator, for example: query?.stepId ?? boot.data?.funnelState?.session?.currentStep.
const initialStepId: string | null = `${query?.stepId}` || boot.data?.funnelState?.session?.currentStep;

@ilasw ilasw requested a review from Copilot April 16, 2025 10:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

position,
skip,
step,
isReady: isInitialized.current,
Copy link

Copilot AI Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using a ref to manage the isReady flag makes it non-reactive, which might lead to components not re-rendering when initialization completes. Consider using useState instead to ensure that changes to isReady trigger a re-render in consuming components.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

packages/shared/src/features/onboarding/hooks/useFunnelNavigation.ts:88

  • [nitpick] Consider renaming 'isInitialized' to 'hasInitialized' for improved clarity, as it indicates whether initialization has occurred.
const isInitialized = useRef<boolean>(false);

packages/shared/src/features/onboarding/hooks/useFunnelNavigation.ts:182

  • The useEffect handling initial navigation includes 'step.id' in its dependency array, which could lead to unintended re-runs if 'step.id' changes after the initial render. Consider revising the dependency array to ensure the effect only runs on mount as intended.
if (initialStepId) {

@ilasw ilasw merged commit 15bb172 into main Apr 17, 2025
2 checks passed
@ilasw ilasw deleted the fix-back-history branch April 17, 2025 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants